package com.example.boot.modules.marketing.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.boot.modules.marketing.entity.CarouselItem;
import com.example.boot.modules.marketing.service.ICarouselItemService;
import com.example.starter.util.Response;
import com.example.starter.webmvc.util.ValidationUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 王令
 * @since 2024/2/27
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/marketing/carousel-item")
public class CarouselItemController {

    private final ICarouselItemService service;

    @PostMapping("/{carouselId}/batch")
    public Response<Void> saveBatch(@PathVariable Long carouselId, @RequestBody List<CarouselItem> items) {
        ValidationUtil.batchValidate(items);
        service.saveBatch(carouselId, items);
        return Response.ok();
    }

    @GetMapping("/{carouselId}/list")
    public Response<List<CarouselItem>> list(@PathVariable Long carouselId) {
        List<CarouselItem> list = service.list(Wrappers.<CarouselItem>lambdaQuery().eq(CarouselItem::getCarouselId, carouselId));
        return Response.ok(list);
    }

}
